package com.lovo.util;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.lovo.dao.IUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;

/**
 * @author lyl
 * description:redis防止缓存穿透，事先进行预防处理
 */
//@Component
public class CacheUtil {
//    @Autowired
//    private static IUserDao iUserDao;

    public static BloomFilter bloomFilter;

    //预先将查询条件进行缓存处理
    static {
        bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.defaultCharset()), 1000000, 0.001);
//        List<UserEntity> list = iUserDao.selectList(null);
//        //将现有用户都放入布隆查询池中
//        for (int i = 0; i < list.size(); i++) {
//            bloomFilter.put("" + list.get(i).getUserId());
//        }
//        bloomFilter.put("1");
    }
}
